package com.eatme.web.security.authentication.emailcode.service.impl;

import com.eatme.web.security.authentication.dao.SecurityUserDao;
import com.eatme.web.security.authentication.domain.entity.SecurityUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service("emailCodeUserDetailsServiceImpl")
@Transactional
public class EmailCodeSecurityUserServiceImpl {
    private static final Logger LOG = LoggerFactory.getLogger(EmailCodeSecurityUserServiceImpl.class);

    private final SecurityUserDao securityUserDao;

    public EmailCodeSecurityUserServiceImpl(SecurityUserDao securityUserDao) {
        this.securityUserDao = securityUserDao;
    }

    public SecurityUser findByEmail(String email) {

        SecurityUser user = securityUserDao.findSecurityUserByList_Identifier(email)
        // 抛UsernameNotFoundException异常
                .orElseThrow(() -> new UsernameNotFoundException("未找到邮箱为"+email+"的用户"));
        return user;
    }

}
